﻿
	using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Linq;
    using System.Linq.Dynamic;
    using System.Text;
    using System.Threading.Tasks;
    using Abp;
    using Abp.Application.Services.Dto;
    using Abp.Authorization;
    using Abp.AutoMapper;
    using Abp.Configuration;
    using Abp.Domain.Repositories;
    using Abp.Extensions;
    using Abp.Linq.Extensions;
    using KDS.Mes.Mes.Plans.Dtos;
using KDS.Mes.DataExporting.Excel.EpPlus;
using Abp.Timing.Timezone;
using Abp.Runtime.Session;
using KDS.Mes.Dto;

namespace KDS.Mes.Mes.Plans
{
    /// <summary>
    /// 计划信息的导出EXCEL功能的实现
    /// </summary>
    public class PlanListExcelExporter : EpPlusExcelExporterBase, IPlanListExcelExporter
    {
     
        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;


        /// <summary>
        /// 构造方法
        /// </summary>
        public PlanListExcelExporter(ITimeZoneConverter timeZoneConverter,     IAbpSession abpSession)
        {
                       _timeZoneConverter = timeZoneConverter;    
                     _abpSession = abpSession;
        }

    

         /// <summary>
        /// 导出计划信息到EXCEL文件
        /// <param name="planListDtos">导出信息的DTO</param>
        /// </summary>
    public    FileDto ExportPlanToFile(List<PlanListDto> planListDtos){


var file=CreateExcelPackage("planList.xlsx",excelPackage=>{

var sheet=excelPackage.Workbook.Worksheets.Add(L("Plan"));
                    sheet.OutLineApplyStyle = true;

                    AddHeader(
                        sheet,
                          L("LineId"),  
     L("AlcCodeId"),  
     L("PlanModeId"),  
     L("Priority"),  
     L("PlanQty"),
      L("Remarks"),
     L("PlanDate"),  
     L("LastModificationTime"),  
     L("CreationTime")  
                        );
         AddObjects(sheet,2,planListDtos,
            
      _ => _.LineName,   
       
      _ => _.AlcCode,   
       
      _ => _.PlanModeCode,   
       
      _ => _.Priority,
        _ => _.PlanQty,
       _ => _.Remarks,

    
       
 _ =>_timeZoneConverter.Convert( _.PlanDate,_abpSession.TenantId, _abpSession.GetUserId()).ToString(),          
 _ =>_timeZoneConverter.Convert( _.LastModificationTime,_abpSession.TenantId, _abpSession.GetUserId()).ToString(),          
 _ =>_timeZoneConverter.Convert( _.CreationTime,_abpSession.TenantId, _abpSession.GetUserId()).ToString()  
);
                    //写个时间转换的吧
          //var creationTimeColumn = sheet.Column(10);
                    //creationTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd";

        for (var i = 1; i <= 8; i++)
                    {
                        sheet.Column(i).AutoFit();
                    }       

});
   return file;

}


 

 
  

    }
    }
